from langchain_openai import ChatOpenAI
from dotenv import load_dotenv
import base64
from pathlib import Path
import os

load_dotenv(override=True)

llm = ChatOpenAI(
    model="qwen-vl-max",
    api_key=os.environ["DASHSCOPE_API_KEY"],
    base_url=os.environ["DASHSCOPE_API_BASE"],
)


with open(
    str(Path(__file__).parent.parent.joinpath("pictures", "cable.png")), "rb"
) as f:
    image = base64.b64encode(f.read()).decode()


MESSAGES = [
    {
        "role": "user",
        "content": [
            {"type": "text", "text": "代表弯曲的线缆是数字几，你只能返回一个数字"},
            {
                "type": "image_url",
                "image_url": {"url": f"data:image/jpg;base64,{image}"},
            },
        ],
    }
]

res = llm.invoke(MESSAGES)

print(res)
